/*
 * Copyright 2017-2021 Pranav Pandey
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.pranavpandey.ohos.dynamic.toasts;

import ohos.agp.components.Component;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.Image;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.StackLayout;
import ohos.agp.components.Text;
import ohos.agp.components.element.Element;
import ohos.agp.components.element.ElementScatter;
import ohos.agp.components.element.PixelMapElement;
import ohos.agp.render.BlendMode;
import ohos.agp.text.Font;
import ohos.agp.utils.Color;
import ohos.agp.utils.LayoutAlignment;
import ohos.agp.window.dialog.ToastDialog;
import ohos.app.Context;
import ohos.global.resource.NotExistException;

import com.pranavpandey.ohos.dynamic.toasts.internal.ToastCompat;
import com.pranavpandey.ohos.dynamic.toasts.watcher.DynamicColorUtils;
import com.pranavpandey.ohos.dynamic.toasts.watcher.DynamicDrawableUtils;

import java.io.IOException;

/**
 * Helper class to display themed {@link ToastDialog} with icon and text.
 * <p>If no color is supplied, it will display default toast based on the vanilla ohos.
 */
public class DynamicToast {
    /**
     * Default background color for the toast.
     */
    private static final int ADT_DEFAULT_BG_COLOR =
        Color.getIntColor("#454545");
    /**
     * Default tint color for the toast.
     */
    private static final int ADT_DEFAULT_TINT_COLOR =
        Color.getIntColor("#FFFFFF");
    /**
     * Default background color for the error toast.
     */
    private static final int ADT_DEFAULT_ERROR_BG_COLOR =
        Color.getIntColor("#F44336");
    /**
     * Default background color for the success toast.
     */
    private static final int ADT_DEFAULT_SUCCESS_BG_COLOR =
        Color.getIntColor("#4CAF50");
    /**
     * Default background color for the warning toast.
     */
    private static final int ADT_DEFAULT_WARNING_BG_COLOR =
        Color.getIntColor("#FFEB3B");
    /**
     * Default value for the {@link #disableIcon}.
     * <p>{@code false} to enable the toast icon.
     */
    private static final boolean ADT_DEFAULT_DISABLE_ICON = false;

    /**
     * Default value for the {@link #tintIcon}.
     * <p>{@code true} to tint the toast icon.
     */
    private static final boolean ADT_DEFAULT_TINT_ICON = true;
    /**
     * Default icon size for the toast in pixels.
     * <p>{@code -1} to use in-built icon size.
     */
    private static final int ADT_DEFAULT_ICON_SIZE = -1;
    /**
     * Default text size for the toast in SP.
     * <p>{@code -1} to use system text size.
     */
    private static final int ADT_DEFAULT_TEXT_SIZE = -1;
    /**
     * Background color for the default toast.
     */
    private static Integer defaultBackgroundColor = ADT_DEFAULT_BG_COLOR;
    /**
     * Tint color for the default toast.
     */
    private static Integer defaultTintColor = ADT_DEFAULT_TINT_COLOR;
    /**
     * Background color for the error toast.
     */
    private static Integer errorBackgroundColor = ADT_DEFAULT_ERROR_BG_COLOR;
    /**
     * Background color for the success toast.
     */
    private static Integer successBackgroundColor =
        ADT_DEFAULT_SUCCESS_BG_COLOR;
    /**
     * Background color for the warning toast.
     */
    private static Integer warningBackgroundColor =
        ADT_DEFAULT_WARNING_BG_COLOR;
    /**
     * Custom icon for the error toast.
     * <p>{@code null} to use the default icon.
     */
    private static Element errorIcon = null;
    /**
     * Custom icon for the success toast.
     * <p>{@code null} to use the default icon.
     */
    private static Element successIcon = null;
    /**
     * Custom icon for the warning toast.
     * <p>{@code null} to use the default icon.
     */
    private static Element warningIcon = null;
    /**
     * {@code true} to disable icon for all the toasts.
     */
    private static boolean disableIcon = ADT_DEFAULT_DISABLE_ICON;
    /**
     * {@code true} to tint icon for all the toasts.
     */
    private static boolean tintIcon = ADT_DEFAULT_TINT_ICON;
    /**
     * Icon size for the toast in pixels.
     */
    private static int iconSize = ADT_DEFAULT_ICON_SIZE;
    /**
     * Text size for the toast in SP.
     */
    private static int textSize = ADT_DEFAULT_TEXT_SIZE;
    /**
     * Custom typeface used by the toast.
     * <p>{@code null} to use the system typeface.
     */
    private static Font textTypeface = null;
    /**
     * Custom background used by the toast.
     * <p>{@code null} to use the default background.
     */
    private static Element toastBackground = null;
    /**
     * the time len for showing toast .
     */
    private static final int LENGTH_SHORT = 8;

    private static final int OFFSET_Y = 200;

    /**
     * Generate tint color according to the supplied color, otherwise return the default value.
     *
     * @param color The color to be used to generate the tint color.
     * @param defaultColor The default value for the tint color.
     * @return The generated tint color according to the supplied color, otherwise return the
     * default value.
     */
    private static Integer generateTintColor(
        Integer color, Integer defaultColor) {
        if (color != null) {
            return DynamicColorUtils.getTintColor(color);
        }

        return defaultColor;
    }

    /**
     * Make a standard toast that just contains a text view.
     *
     * @param context The context to use.
     * @param text The text to show. Can be formatted text.
     * @return The toast with the supplied parameters.
     */
    public static ToastDialog make(Context context, CharSequence text) {
        return make(context, text, null, defaultTintColor,
            defaultBackgroundColor, LENGTH_SHORT);
    }

    /**
     * Make a standard toast with icon and the text.
     *
     * @param context The context to use.
     * @param text The text to show. Can be formatted text.
     * @param duration The duration for the toast
     * @return The toast with the supplied parameters.
     */
    public static ToastDialog make(Context context, CharSequence text, int duration) {
        return make(context, text, null, defaultTintColor,
            defaultBackgroundColor, duration);
    }

    /**
     * Make a error toast with icon and the text.
     *
     * @param context The context to use.
     * @param text The text to show. Can be formatted text.
     * @return The toast with the supplied parameters.
     * @throws IOException
     * @throws NotExistException
     */
    public static ToastDialog makeError(Context context, CharSequence text)
        throws IOException, NotExistException {
        PixelMapElement mapElement = new PixelMapElement(context.getResourceManager()
            .getResource(ResourceTable.Media_adt_ic_error));
        return make(context, text, errorIcon != null ? errorIcon : mapElement,
            generateTintColor(errorBackgroundColor, defaultTintColor), errorBackgroundColor);
    }

    /**
     * Make a error toast with icon and the text.
     *
     * @param context The context to use.
     * @param text The text to show. Can be formatted text.
     * @param duration The duration for the toast
     * @return The toast with the supplied parameters.
     * @throws IOException io exception
     * @throws NotExistException not file exist exception
     */
    public static ToastDialog makeError(Context context, CharSequence text, int duration)
        throws IOException, NotExistException {
        PixelMapElement mapElement = new PixelMapElement(context.getResourceManager()
            .getResource(ResourceTable.Media_adt_ic_error), false);
        return make(context, text, mapElement, generateTintColor(errorBackgroundColor, defaultTintColor),
            errorBackgroundColor, duration);
    }

    /**
     * Make a success toast with icon and the text.
     *
     * @param context The context to use.
     * @param text The text to show. Can be formatted text.
     * @return The toast with the supplied parameters.
     * @throws IOException io exception
     * @throws NotExistException not file exist exception
     */
    public static ToastDialog makeSuccess(Context context, CharSequence text)
        throws IOException, NotExistException {
        PixelMapElement mapElement = new PixelMapElement(context.getResourceManager()
            .getResource(ResourceTable.Media_adt_ic_success));
        return make(context, text, successIcon != null ? successIcon : mapElement,
            generateTintColor(successBackgroundColor, defaultTintColor), successBackgroundColor);
    }

    /**
     * Make a success toast with icon and the text.
     *
     * @param context The context to use.
     * @param text The text to show. Can be formatted text.
     * @param duration The duration for the toast
     * @return The toast with the supplied parameters.
     * @throws IOException io exception
     * @throws NotExistException not file exist exception
     */
    public static ToastDialog makeSuccess(Context context, CharSequence text, int duration)
        throws IOException, NotExistException {
        PixelMapElement mapElement = new PixelMapElement(context.getResourceManager()
            .getResource(ResourceTable.Media_adt_ic_success));
        return make(context, text, mapElement, generateTintColor(successBackgroundColor, defaultTintColor),
            successBackgroundColor, duration);
    }

    /**
     * Make a warning toast with icon and the text.
     *
     * @param context The context to use.
     * @param text The text to show. Can be formatted text.
     * @return toastDialog
     * @throws IOException io exception
     * @throws NotExistException not file exist exception
     */
    public static ToastDialog makeWarning(Context context, CharSequence text)
        throws IOException, NotExistException {
        PixelMapElement mapElement = new PixelMapElement(context.getResourceManager()
            .getResource(ResourceTable.Media_adt_ic_warning));
        return make(context, text, warningIcon != null ? warningIcon : mapElement,
            generateTintColor(warningBackgroundColor, defaultTintColor), warningBackgroundColor);
    }

    /**
     * Make a warning toast with icon and the text.
     *
     * @param context The context to use.
     * @param text The text to show. Can be formatted text.
     * @param duration The duration for the toast, either
     * @return toastDialog
     * @throws IOException io exception
     * @throws NotExistException not file exist exception
     */
    public static ToastDialog makeWarning(Context context, CharSequence text, int duration)
        throws IOException, NotExistException {
        PixelMapElement mapElement = new PixelMapElement(context.getResourceManager()
            .getResource(ResourceTable.Media_adt_ic_warning));
        return make(context, text, mapElement,
            generateTintColor(warningBackgroundColor, defaultTintColor),
            warningBackgroundColor, duration);
    }

    /**
     * Make a error toast with icon and the text.
     *
     * @param context The context to use.
     * @param text The text to show. Can be formatted text.
     * @param icon The toast icon to show.
     * @return The toast with the supplied parameters.
     */
    public static ToastDialog make(Context context, CharSequence text, Element icon) {
        return make(context, text, icon, defaultTintColor,
            defaultBackgroundColor, LENGTH_SHORT);
    }

    /**
     * Make a themed toast with icon and the text.
     *
     * @param context The context to use.
     * @param text The text to show. Can be formatted text.
     * @param icon The toast icon to show.
     * @param duration The duration for the toast, either ToastDialog
     * @return The toast with the supplied parameters.
     */
    public static ToastDialog make(Context context, CharSequence text, Element icon, int duration) {
        return make(context, text, icon, defaultTintColor, defaultBackgroundColor, duration);
    }

    /**
     * Make a themed toast with icon and the text.
     *
     * @param context The context to use.
     * @param text The text to show. Can be formatted text.
     * @param tintColor The toast tint color based on the toast background.
     * <p>It will automatically check for the contrast to provide best visibility.
     * @param backgroundColor The toast background color.
     * @return The toast with the supplied parameters.
     */
    public static ToastDialog make(Context context, CharSequence text,
        Integer tintColor, Integer backgroundColor) {
        return make(context, text, null, tintColor, backgroundColor, LENGTH_SHORT);
    }

    /**
     * Make a themed toast with text, background and the tint color.
     *
     * @param context The context to use.
     * @param text The text to show. Can be formatted text.
     * @param tintColor The toast tint color based on the toast background.
     * <p>It will automatically check for the contrast to provide best visibility.
     * @param backgroundColor The toast background color
     * @param duration The duration for the toast, eitherToastDialog
     * @return The toast with the supplied parameters.
     * <p>Use ToastDialog to display the toast.
     */
    public static ToastDialog make(Context context,
        CharSequence text, Integer tintColor, Integer backgroundColor, int duration) {
        return make(context, text, null, tintColor, backgroundColor, duration);
    }

    /**
     * Make a themed toast with text, icon, background and the tint color.
     * <p>The toast duration will be ToastDialog
     *
     * @param context The context to use.
     * @param text The text to show. Can be formatted text.
     * @param icon The toast icon to show.
     * @param tintColor The toast tint color based on the toast background.
     * <p>It will automatically check for the contrast to provide best visibility.
     * @param backgroundColor The toast background color.
     * @return The toast with the supplied parameters.
     * <p>Use {@link ToastDialog#show()} to display the toast.
     */
    public static ToastDialog make(Context context, CharSequence text,
        Element icon, Integer tintColor, Integer backgroundColor) {
        return make(context, text, icon, tintColor, backgroundColor, LENGTH_SHORT);
    }

    /**
     * Make a themed toast with text, icon, background and the tint color.
     *
     * @param context The context to use.
     * @param text The text to show. Can be formatted text.
     * @param icon The toast icon to show.
     * @param tintColor The toast tint color based on the toast background.
     * <p>It will automatically check for the contrast to provide best visibility.
     * @param backgroundColor The toast background color.
     * @param duration The duration for the toast, either ToastDialog
     * @return The toast with the supplied parameters.
     * <p>Use ToastDialog to display the toast.
     */
    public static ToastDialog make(Context context, CharSequence text, Element icon,
        Integer tintColor, Integer backgroundColor, int duration) {
        Integer toastTintColor = tintColor;
        if (tintColor != null && backgroundColor != null) {
            toastTintColor = DynamicColorUtils.getContrastColor(toastTintColor, backgroundColor);
        }
        StackLayout toastLayout = (StackLayout) LayoutScatter.getInstance(context)
            .parse(com.pranavpandey.ohos.dynamic.toasts.ResourceTable.Layout_adt_layout_toast, null, false);
        ToastCompat toast = new ToastCompat(context, new ToastDialog(context));
        Image toastIcon = (Image) toastLayout.findComponentById(ResourceTable.Id_adt_toast_icon);
        Text toastText = (Text) toastLayout.findComponentById(ResourceTable.Id_adt_toast_text);
        if (!disableIcon && icon != null) {
            if (iconSize != ADT_DEFAULT_ICON_SIZE) {
                toastIcon.setWidth(iconSize);
                toastIcon.setHeight(iconSize);
            }
            if (tintIcon && toastTintColor != null) {
                ImageTint.setImageTint(toastIcon, icon, toastTintColor, BlendMode.SRC_ATOP);
            } else {
                toastIcon.setImageElement(icon);
            }
        } else {
            toastIcon.setVisibility(Component.HIDE);
        }
        if (textTypeface != null) {
            toastText.setFont(textTypeface);
        }
        if (textSize != ADT_DEFAULT_TEXT_SIZE) {
            toastText.setTextSize(textSize, Text.TextSizeType.FP);
        }
        if (toastTintColor != null) {
            Color color = new Color(toastTintColor);
            toastText.setTextColor(color);
        }
        toastText.setText(String.valueOf(text));
        if (toastBackground != null) {
            DynamicDrawableUtils.setBackground(toastLayout, backgroundColor != null
                ? DynamicDrawableUtils.colorizeElement(toastBackground,
                backgroundColor, BlendMode.MULTIPLY) : toastBackground);
        } else {
            Element element = ElementScatter.getInstance(context).parse(ResourceTable.Graphic_adt_toast_background);
            DynamicDrawableUtils.setBackground(toastLayout, backgroundColor != null
                ? DynamicDrawableUtils.colorizeElement(element, backgroundColor, BlendMode.MULTIPLY) : element);
        }
        toast.setDuration(duration);
        toast.setSize(DirectionalLayout.LayoutConfig.MATCH_CONTENT, DirectionalLayout.LayoutConfig.MATCH_CONTENT);
        toast.setAlignment(LayoutAlignment.BOTTOM | LayoutAlignment.CENTER);
        toast.setOffset(0, OFFSET_Y);
        toast.setComponent(toastLayout);
        return toast;
    }

    /**
     * Configuration class to customise the  DynamicToast attributes.
     *
     * @since 2021-07-13
     */
    public static class Config {
        /**
         * Singleton instance of {@link Config}.
         */
        private static Config sInstance;

        /**
         * Background color for the default toast.
         */
        private Integer defaultBackgroundColor = DynamicToast.defaultBackgroundColor;

        /**
         * Tint color for the default toast.
         */
        private Integer defaultTintColor = DynamicToast.defaultTintColor;

        /**
         * Background color for the error toast.
         */
        private Integer errorBackgroundColor = DynamicToast.errorBackgroundColor;

        /**
         * Background color for the success toast.
         */
        private Integer successBackgroundColor = DynamicToast.successBackgroundColor;

        /**
         * Background color for the warning toast.
         */
        private Integer warningBackgroundColor = DynamicToast.warningBackgroundColor;

        /**
         * Custom icon for the error toast.
         */
        private Element errorIcon = DynamicToast.errorIcon;

        /**
         * Custom icon for the success toast.
         */
        private Element successIcon = DynamicToast.successIcon;

        /**
         * Custom icon for the warning toast.
         */
        private Element warningIcon = DynamicToast.warningIcon;

        /**
         * {@code true} to disable icon for all the toasts.
         */
        private boolean disableIcon = DynamicToast.disableIcon;

        /**
         * {@code true} to tint icon for all the toasts.
         */
        private boolean tintIcon = DynamicToast.tintIcon;

        /**
         * Icon size for the toast in pixels.
         */
        private int iconSize = DynamicToast.iconSize;

        /**
         * Text size for the toast in SP.
         */
        private int textSize = DynamicToast.textSize;

        /**
         * Custom text typeface used by the toast.
         */

        private Font textTypeface = null;

        /**
         * Custom background used by the toast.
         */
        private Element toastBackground = null;

        /**
         * Making default constructor private to avoid instantiation.
         */
        private Config() {
        }

        /**
         * Get instance to access public methods. Must be called before accessing methods.
         *
         * @return The singleton instance of this class.
         */
        public static Config getInstance() {
            if (sInstance == null) {
                sInstance = new Config();
            }

            return sInstance;
        }

        /**
         * Get instance to access public methods. Must be called before accessing methods.
         *
         * @param sInstance The singleton instance of this class.
         */
        public static void setsInstance(Config sInstance) {
            Config.sInstance = sInstance;
        }

        /**
         * Set the default background color.
         *
         * @param defaultBackgroundColor The background color to be set.
         * @return The {@link Config} object to allow for chaining of calls to set methods.
         */
        public Config setDefaultBackgroundColor(
            Integer defaultBackgroundColor) {
            this.defaultBackgroundColor = defaultBackgroundColor;

            return this;
        }

        /**
         * Set the default tint color.
         *
         * @param defaultTintColor The tint color to be set.
         * @return The {@link Config} object to allow for chaining of calls to set methods.
         */
        public Config setDefaultTintColor(Integer defaultTintColor) {
            this.defaultTintColor = defaultTintColor;

            return this;
        }

        /**
         * Set the error background color.
         *
         * @param errorBackgroundColor The error background color to be set.
         * @return The {@link Config} object to allow for chaining of calls to set methods.
         */
        public Config setErrorBackgroundColor(
            Integer errorBackgroundColor) {
            this.errorBackgroundColor = errorBackgroundColor;

            return this;
        }

        /**
         * Set the success background color.
         *
         * @param successBackgroundColor The success background color to be set.
         * @return The {@link Config} object to allow for chaining of calls to set methods.
         */
        public Config setSuccessBackgroundColor(
            Integer successBackgroundColor) {
            this.successBackgroundColor = successBackgroundColor;
            return this;
        }

        /**
         * Set the warning background color.
         *
         * @param warningBackgroundColor The warning background color to be set.
         * @return The {@link Config} object to allow for chaining of calls to set methods.
         */
        public Config setWarningBackgroundColor(
            Integer warningBackgroundColor) {
            this.warningBackgroundColor = warningBackgroundColor;
            return this;
        }

        /**
         * Set the error icon.
         * <p>Pass {@code null} to use the default icon.
         *
         * @param errorIcon The error icon to be set.
         * @return The {@link Config} object to allow for chaining of calls to set methods.
         */
        public Config setErrorIcon(Element errorIcon) {
            this.errorIcon = errorIcon;
            return this;
        }

        /**
         * Set the success icon.
         * <p>Pass {@code null} to use the default icon.
         *
         * @param successIcon The success icon to be set.
         * @return The {@link Config} object to allow for chaining of calls to set methods.
         */
        public Config setSuccessIcon(Element successIcon) {
            this.successIcon = successIcon;
            return this;
        }

        /**
         * Set the warning icon.
         * <p>Pass {@code null} to use the default icon.
         *
         * @param warningIcon The warning icon to be set.
         * @return The {@link Config} object to allow for chaining of calls to set methods.
         */
        public Config setWarningIcon(Element warningIcon) {
            this.warningIcon = warningIcon;
            return this;
        }

        /**
         * Set the icon visibility.
         *
         * @param disableIcon {@code true} to disable icon for all the toasts.
         * @return The {@link Config} object to allow for chaining of calls to set methods.
         */
        public Config setDisableIcon(boolean disableIcon) {
            this.disableIcon = disableIcon;
            return this;
        }

        /**
         * Set whether to tint the icon.
         *
         * @param tintIcon {@code true} to tint icon for all the toasts.
         * @return The {@link Config} object to allow for chaining of calls to set methods.
         */
        public Config setTintIcon(boolean tintIcon) {
            this.tintIcon = tintIcon;
            return this;
        }

        /**
         * Set the icon size.
         *
         * @param iconSize The icon size to be set in {@code pixels}.
         * @return The {@link Config} object to allow for chaining of calls to set methods.
         */
        public Config setIconSize(int iconSize) {
            this.iconSize = iconSize;
            return this;
        }

        /**
         * Set the text size.
         *
         * @param textSize The text size to be set in {@code sp}.
         * @return The {@link Config} object to allow for chaining of calls to set methods.
         */
        public Config setTextSize(int textSize) {
            this.textSize = textSize;
            return this;
        }

        /**
         * Set the text typeface.
         * <p>Pass {@code null} to use the default typeface.
         *
         * @param textTypeface The text typeface to be set.
         * @return The {@link Config} object to allow for chaining of calls to set methods.
         */
        public Config setTextTypeface(Font textTypeface) {
            this.textTypeface = textTypeface;
            return this;
        }

        /**
         * Set the toast background.
         * <p>Pass {@code null} to use the default background.
         *
         * @param toastBackground The toast background to be set.
         * @return The {@link Config} object to allow for chaining of calls to set methods.
         */
        public Config setToastBackground(Element toastBackground) {
            this.toastBackground = toastBackground;
            return this;
        }

        /**
         * Apply customisations.
         */
        public void apply() {
            DynamicToast.defaultBackgroundColor = defaultBackgroundColor;
            DynamicToast.defaultTintColor = defaultTintColor;
            DynamicToast.errorBackgroundColor = errorBackgroundColor;
            DynamicToast.successBackgroundColor = successBackgroundColor;
            DynamicToast.warningBackgroundColor = warningBackgroundColor;
            DynamicToast.errorIcon = errorIcon;
            DynamicToast.successIcon = successIcon;
            DynamicToast.warningIcon = warningIcon;
            DynamicToast.disableIcon = disableIcon;
            DynamicToast.tintIcon = tintIcon;
            DynamicToast.iconSize = iconSize;
            DynamicToast.textSize = textSize;
            DynamicToast.textTypeface = textTypeface;
            DynamicToast.toastBackground = toastBackground;
            setsInstance(null);
        }

        /**
         * Reset customisations.
         */
        public void reset() {
            DynamicToast.defaultBackgroundColor = ADT_DEFAULT_BG_COLOR;
            DynamicToast.defaultTintColor = ADT_DEFAULT_TINT_COLOR;
            DynamicToast.errorBackgroundColor = ADT_DEFAULT_ERROR_BG_COLOR;
            DynamicToast.successBackgroundColor = ADT_DEFAULT_SUCCESS_BG_COLOR;
            DynamicToast.warningBackgroundColor = ADT_DEFAULT_WARNING_BG_COLOR;
            DynamicToast.errorIcon = null;
            DynamicToast.successIcon = null;
            DynamicToast.warningIcon = null;
            DynamicToast.disableIcon = ADT_DEFAULT_DISABLE_ICON;
            DynamicToast.tintIcon = ADT_DEFAULT_TINT_ICON;
            DynamicToast.iconSize = ADT_DEFAULT_ICON_SIZE;
            DynamicToast.textSize = ADT_DEFAULT_TEXT_SIZE;
            DynamicToast.textTypeface = null;
            DynamicToast.toastBackground = null;

            setsInstance(null);
        }
    }
}
